<?php

App::uses('AppModel', 'Model');

class FinanceCycle extends AppModel {
    
    public $validate = array(
        'date'   => array('rule'=>'date',    'message'=>STR_REQUIRED_FIELD),
        'amount' => array('rule'=>'decimal', 'message'=>STR_INVALID_FIELD)
    );
    
    public function getLast($date) {
        return Set::extract($this->name, $this->find('first', array(
            'conditions' => array(
                'date <=' => $date
            ),
            'order' => 'date DESC',
            'fields' => array('date', 'amount')
        )));
    }
    
}

?>